﻿// Write a program that reads two numbers N and K and generates all the variations of K elements from the set [1..N]. 
// Example: N = 3, K = 2  {1, 1}, {1, 2}, {1, 3}, {2, 1}, {2, 2}, {2, 3}, {3, 1}, {3, 2}, {3, 3}
using System;

class VariationsOfKElementFromSet
{
    static void Main()
    {
        uint numberN;
        do
        {
            Console.Write("Enter number N: ");
        } while (!uint.TryParse(Console.ReadLine(), out numberN));

        uint numberK;
        do
        {
            Console.Write("Enter number K: ");
        } while (!uint.TryParse(Console.ReadLine(), out numberK));

        uint[] variationsArray = new uint[numberK];
        GetVariations(variationsArray, 0, numberN);
    }

    private static void GetVariations(uint[] variationsArray, uint index, uint numberN)
    {
        if (index == variationsArray.Length)
        {
            PrintArray(variationsArray);
        }
        else
        {
            for (uint i = 1; i <= numberN; i++)
            {
                variationsArray[index] = i;
                GetVariations(variationsArray, index + 1, numberN);
            }
        }
    }

    private static void PrintArray(uint[] array)
    {
        Console.Write("{");
        for (uint i = 0; i < array.Length; i++)
        {
            Console.Write(array[i]);
            if (i != array.Length - 1)
            {
                Console.Write(", ");
            }
        }
        Console.WriteLine("}");
    }
}